﻿using System;
using System.Collections.Generic;
using System.Text;
using WcfContract;
using System.ServiceModel;
using System.Threading;
using System.IO;

namespace TestServer
{
    class CustomStream : Stream
    {
        int position = 0;
 
        public override bool CanRead
        {
            get { return true; }
        }

        public override bool CanSeek
        {
            get { return false; }
        }

        public override bool CanWrite
        {
            get { return false; }
        }

        public override void Flush()
        {
            throw new Exception("This stream does not support writing.");
        }

        public override long Length
        {
            get { throw new Exception("This stream does not support the Length property."); }
        }

        public override long Position
        {
            get
            {
                return position;
            }
            set
            {
                throw new Exception("This stream does not support setting the Position property.");
            }
        }

        public override int Read(byte[] buffer, int offset, int count)
        {
            if (position > 10000)
                return 0;
            position += count;
            return count;
        }

        public override int ReadByte()
        {
            return base.ReadByte();
        }

        public override long Seek(long offset, SeekOrigin origin)
        {
            throw new Exception("This stream does not support seeking.");
        }

        public override void SetLength(long value)
        {
            throw new Exception("This stream does not support setting the Length.");
        }

        public override void Write(byte[] buffer, int offset, int count)
        {
            throw new Exception("This stream does not support writing.");
        }
        public override void Close()
        {
            base.Close();
        }
        protected override void Dispose(bool disposing)
        {
                base.Dispose(disposing);
        }
    }
}
